package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Controller
public class PageController {
    @Autowired
    private PageService pageService;
    /*
    * 跳转到商品详情页
    * @param model
    * @param 商品spuid
    * @return 页面名称
    * */
    @GetMapping("item/{id}.html")
    public String toItemPage(Model model, @PathVariable("id")Long id){
        //加载数据
        Map<String,Object> itemData=pageService.loadItemData(id);
        //向model中加入数据
        model.addAllAttributes(itemData);
        //生成静态页
        pageService.createItemHtml(id);
        return "item";
    }


}
